import {message} from 'antd';
import {formatMessage} from './intl';
export const newOrUpdateOrderValidator = (data, details, type, brands) => {
    const requiredFields = [];
    if(brands.length > 1)
        if(!data.brandId)
            requiredFields.push(formatMessage({
                id: 'validator.message.brandId',
                defaultMessage: '请先选择品牌'
            }));
    if(!data.dealerId)
        requiredFields.push(formatMessage({
            id: 'validator.message.dealerId',
            defaultMessage: '请先选择总代'
        }));
    if(!data.transportType)
        requiredFields.push(formatMessage({
            id: 'validator.message.transportType',
            defaultMessage: '请先选择运输方式'
        }));
    if(!data.expectDepartedDate)
        requiredFields.push(formatMessage({
            id: 'validator.message.expectDepartedDate',
            defaultMessage: '请先选择预计离港日期'
        }));
    if(data.expectDepartedDate > data.expectArrivalDate) {
        message.warning(`${formatMessage({
            id: 'validator.message.expectDeparteArrivalDate',
            defaultMessage: '预计离港日期不能大于预计到港日期'
        })}`);
        return false;
    }
    if(data.actualDepartedDate > data.actualArrivalDate) {
        message.warning(`${formatMessage({
            id: 'validator.message.actualDeparteArrivalDate',
            defaultMessage: '实际离港日期不能大于实际到港日期'
        })}`);
        return false;
    }
    if(type === 'type') {
        if(!details || (details && details.length === 0)) {
            message.warning(formatMessage({
                id: 'validator.message.detailQuantity',
                defaultMessage: '清单不能为空！'
            }));
            return false;
        }
        if(details.some(d => !d.salePackingListCode))
            requiredFields.push(formatMessage({
                id: 'validator.empty.salePackingListCode',
                defaultMessage: '包装箱单号'
            }));
        if(details.some(d => !d.palletCode))
            requiredFields.push(formatMessage({
                id: 'validator.empty.palletCode',
                defaultMessage: '包装箱单托盘号'
            }));
        if(details.some(d => !d.saleConfirmationCode))
            requiredFields.push(formatMessage({
                id: 'validator.empty.saleConfirmationCode',
                defaultMessage: '销售确认书编号'
            }));
        if(details.some(d => !d.partCode))
            requiredFields.push(formatMessage({
                id: 'validator.empty.partCode',
                defaultMessage: '零件编号'
            }));
        if(details.some(d => !d.quantity))
            requiredFields.push(formatMessage({
                id: 'validator.empty.quantity',
                defaultMessage: '数量'
            }));
    }
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.message.required',
            defaultMessage: '必填!'
        })}`);
        return false;
    }
    return true;
};
